package com.yunqing.restkeeper.enterprise.web.controller.shop;

import com.yunqing.restkeeper.enterprise.web.vo.shop.AddBrandVO;
import com.yunqing.restkeeper.shop.api.entity.Brand;
import com.yunqing.restkeeper.shop.api.service.IBrandService;
import com.yunqing.restkeeper.web.common.response.vo.PageVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @ClassName BrandController
 * @Description TODO
 * @author: puyunqing
 * @Date: 2025/7/3
 */
@Slf4j
@Tag(name = "品牌管理")
@RestController
@RequestMapping("/brand")
public class BrandController {


    @DubboReference(version = "1.0.0", check = false)
    private IBrandService brandService;

    @Operation(summary = "分页查询所有品牌信息")
    @Parameters({
            @Parameter(in = ParameterIn.PATH, name = "page", description = "当前页码", required = false, schema = @Schema(type = "Integer")),
            @Parameter(in = ParameterIn.PATH, name = "pageSize", description = "分大小", required = false, schema = @Schema(type = "Integer"))})
    @GetMapping("/pageList/{page}/{pageSize}")
    public PageVO<Brand> pageList(@PathVariable("page") int page, @PathVariable("pageSize") int pageSize) {

        return new PageVO<Brand>(brandService.queryPage(page, pageSize));
    }

    @Operation(summary = "新增品牌")
    @PostMapping("/add")
    public boolean add(@RequestBody AddBrandVO addTBrandVO){
        Brand brand = new Brand();
        BeanUtils.copyProperties(addTBrandVO,brand);
        return brandService.save(brand);
    }

    @Operation(summary = "品牌列表（下拉选择使用）")
    @GetMapping("/brandList")
    @ResponseBody
    public List<Map<String, Object>> list() {
        return brandService.getBrandList();
    }
}
